<template>
  <div>
    <el-main>
       <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="研究方向" name="first">
            <el-row>
              <el-col>
                <el-button type="primary" v-if="is_admin_view == 0" @click="addFieldVisible = true">添加研究领域</el-button>
                <!-- <el-button type="primary" >添加专利</el-button> -->
                <span style="font-size:14px;margin-left: 20px;">更新周期：{{data.start_time}} 至 {{data.end_time}}</span>
              </el-col>
            </el-row>
            <CreatTable :ListArr="ListArr" :handelType="handelType"  @deletUsers="deletUsers" :title="name" :is_fa='is_fa'/>
          </el-tab-pane>
          <el-tab-pane label="发明人" name="second">
            <el-row>
              <el-col>
                <el-button type="primary" v-if="is_admin_view == 0" @click="addInventorVisible = true">添加发明人</el-button>
                <!-- <el-button type="primary" >添加专利</el-button> -->
                <span style="font-size:14px;margin-left: 20px;">更新周期：{{data.start_time}} 至 {{data.end_time}}</span>
              </el-col>
            </el-row>
            <CreatTable :ListArr="ListArr" :handelType="handelType"   @deletUsers="deletUsers" :title="name2" :is_fa='is_fa'/>
          </el-tab-pane>
        </el-tabs>
    </el-main>
    <Service/>
    <el-dialog
    :destroy-on-close="true"
     :close-on-click-modal='false'
      title="添加研究领域"
      :visible.sync="addFieldVisible"
      width="40%"
      center
      @close="cancleFieldVisible('Field')"
      >
     <el-form :model="Field" ref="Field"  label-width="120px" label-position="left">
          <el-form-item prop="Value" label="研究方向关键词">
            <el-input type="Value"  v-model="Field.Value" placeholder="请输入研究方向关键词"></el-input>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="button" class="pubBtn2" @click="cancleFieldVisible('Field')">取消添加</el-button>
        <el-button type="button" class="pubBtn" @click="addField('Field')">确定添加</el-button>
      </span>
    </el-dialog>
    <el-dialog
    :destroy-on-close="true"
     :close-on-click-modal='false'
      title="添加产学研发明人"
      :visible.sync="addInventorVisible"
      width="40%"
      center
      @close="cancleInventorVisible('Inventor')"
      >
      <el-form ref="Inventor" :model="Inventor" label-width="120px" label-position="left">
          <el-form-item prop="name" label="发明人姓名">
            <el-input style="width:87%;" v-model="Inventor.name" placeholder="请输入发明人姓名">
            </el-input>
            <el-button @click='search' type="primary">搜索</el-button>
          </el-form-item>
          <el-form-item prop="school" label="发明人所在院校">
            <!-- <el-input  v-model="Inventor.school" placeholder="请输入发明人所在院校"></el-input> -->
           <el-select multiple v-model="Inventor.school" placeholder="请选择发明人所在院校">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="button" class="pubBtn2" @click="cancleInventorVisible('Inventor')">取消添加</el-button>
        <el-button type="button" class="pubBtn" @click="addInventor('Inventor')">确定添加</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {mapGetters} from 'vuex'
  import {infoList,patentIndex2} from "@/api"
  import {patentCreateYan,patentCollage,delYan} from "@/api/user"
  import CreatTable from "@/components/CreatTable/CreatTable"
  import Service from '@/components/Service'
  export default {
    data() {
      return {
        is_fa:0,
        addVal:"",
        dialogVisible:false,
        addFieldVisible:false,
        addInventorVisible:false,
        ListArr:[],
        currentPage: 1, //默认显示页面为1
        pagesize: 10, //    每页的数据条数
        page:[],
        handelType:3,
        data:[],
        // name:'研究方向',
        name2:'发明人',
        activeName: 'first',
        FieldValue:'',
        Inventor:{
          name:'',
          school:[],
        },
        options: [],
        Field:{
          Value:''
        },
        numberValidateForm: {
          age: ''
        },
      }
    },
    components:{
      CreatTable,
      Service
    },
    computed:{
     ...mapGetters([
       'sidebar',
       'avatar',
       'name',
       'roles',
       'type',
       'is_admin_view'
     ]),
    },
    mounted() {
        this.getList();
    },

    methods:{
      async getList(){
        try{
          const res =await patentIndex2({type:2});
           this.ListArr = res.list_all;
           this.data = res
          this.page = res.page
        } catch(e){
          this.$message.error(e.message);
        }
      },
      rowClick(row){
      },
      async search(){
        const res = await patentCollage({
          name:this.Inventor.name
        })
        this.options = res.options
      },
      async handleClick(tab){
        try{
          if(tab.index == 0){
            const res =await patentIndex2({type:2,is_fa:0});
             this.ListArr = res.list_all;
             this.data = res
            this.page = res.page
            this.is_fa = 0
          }else{
            const res =await patentIndex2({is_fa:1,type:2});
             this.ListArr = res.list_all;
             this.data = res
            this.page = res.page
            this.is_fa = 1
          }
        } catch(e){
          this.$message.error(e.message);
        }
      },
      async addField(formName){
          try{
            const res = await patentCreateYan({
               keyword:this.Field.Value,
            })
             this.getList();
             this.addFieldVisible = false;
             this.$refs[formName].resetFields();
             this.options = []
             this.$message.success("添加成功")
          } catch (e){
            this.$message.error(e.message)
          }
      },
      cancleFieldVisible(formName){
        this.addFieldVisible = false;
        this.$refs[formName].resetFields();
      },
      async addInventor(formName){
        try{
         await patentCreateYan({
             keyword:this.Inventor.school,
             names:this.Inventor.name,
             is_fa:1
          })
          const res =await patentIndex2({is_fa:1,type:2});
           this.ListArr = res.list_all;
           this.is_fa = 1
           this.data = res
          this.page = res.page
           this.addInventorVisible = false;
           this.$refs[formName].resetFields();
           this.options = []
           this.$message.success("添加成功")
        } catch (e){
          this.$message.error(e.message)
        }
      },
      cancleInventorVisible(formName){
        this.addInventorVisible = false;
        this.$refs[formName].resetFields()
        this.options = []
      },
      // //每页下拉显示数据
      // async handleSizeChange(size) {
      //   try{
      //     const res =await infoList({
      //        page:size,
      //     })
      //     this.ListArr = res.list;
      //     this.page = res.page
      //   } catch (e){
      //     this.$message.error(e.message)
      //   }

      // },
      // //点击第几页
      // async handleCurrentChange(currentPage) {
      //   try{
      //     const res =await infoList({
      //        page:currentPage,
      //     })
      //     this.ListArr = res.list;
      //     this.page = res.page
      //   } catch (e){
      //     this.$message.error(e.message)
      //   }
      // },
      handleClose(){
        this.dialogVisible = false
        this.options = []
      },
      async addSave(){
        try{
          await rivalsAdd({name:this.addVal})
          this.getList();
          this.dialogVisible = false
          this.$message.success("添加成功")
        } catch (e){
          this.$message.error(e.message)
        }
      },
      async deletUsers(id){
        try{
          this.$confirm('确定不再关注吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(async () => {
            await delYan({sales_id:id})
            this.getList();
            this.$message.success("添加成功")
          }).catch(() => {
          });
        } catch (e){
          this.$message.error(e.message)
        }
      },
      // see(name){
      //   this.$router.push({path:"/cutDetails",query:{name:id,type:2}})
      // }
    }
  }
</script>

<style scoped lang="less">
 .diff{
   color:#F05C6C;
 }
 .el-select{
   width:100%;
 }
</style>
